import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025/2/16
 */
public class leetcode_118 {
    public static void main(String[] args) {
        generate(5);
    }

    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> resList = new ArrayList<>();
        if(numRows==0){
            return new ArrayList<>();
        }
        if(numRows==1){
            ArrayList<Integer> list = new ArrayList<>();
            list.add(1);
            return new ArrayList<List<Integer>>(Collections.singleton(list));
        }
        int[][] dp = new int[numRows][];
        for (int i = 0; i < numRows; i++) {
            dp[i] = new int[i+1];
            dp[i][0]=1;
            dp[i][i] = 1;
        }
        for (int i = 1; i < numRows; i++) {
            for (int j = 1; j < i; j++) {
                dp[i][j] = dp[i-1][j-1]+dp[i-1][j];
            }
        }
        for (int i = 0; i < numRows; i++) {
            ArrayList<Integer> list = new ArrayList<>();
            for (int j = 0; j < i+1; j++) {
                list.add(dp[i][j]);
            }
            resList.add(list);
        }
        return resList;
    }

}
